<?php
global $options;
foreach ($options as $value) {
    if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}
$dateformat = get_option('date_format');
$timeformat = get_option('time_format');
$layout = get_post_meta($post->ID, 'template', true);
get_header(); 

//staff variables
$staff_id = get_cat_ID( 'Staff' );
$staff_link = get_category_link( $staff_id );
?>

  <div id="content">
    <div class="wrap">
    
      <?php wp_reset_query(); 
      if (have_posts()) : while (have_posts()) : the_post(); ?>
	  
      <?php if ($layout != 'full') { ?>
      <div class="column column-narrow">
      
      	<?php 
      	$currCat = get_the_category();
      	$current = $currCat[0]->name;
      	$parent = get_cat_name($currCat[0]->category_parent);
      	
    	echo "<p class='heading'>".$parent."</p>";		
		list_cat_posts_all();
		?>
      
        <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar: Posts (Left)') ) : ?>&nbsp;<?php endif; ?>
      
      </div><!-- end .column-narrow -->
      <?php } ?>
      
      <div class="column <?php if ($layout == 'double') {echo"column-double column-last ";} if ($layout == 'full') {echo"column-full column-last ";} ?>column-content column-double">
	  	<div id="crumbs">
			<!--?php the_breadcrumb(); ?-->
			<?php
				$args = array(
					'prefix' => '<p>',
					'suffix' => '</p>',
					'title' => __( '', 'breadcrumbs-plus' ),
					'home' => __( 'Home', 'breadcrumbs-plus' ),
					'sep' => '»',
					'front_page' => false,
					'bold' => true,
					'show_blog' => false,
					'echo' => true,
					'singular_post_taxonomy' => 'category',
				);
				breadcrumbs_plus( $args );
			?>
		</div>
		<h1><?php the_title(); ?></h1>
        
        <?php
		$args = array(
			'category_name' => 'people', 
			'meta_key' => 'general_detail_if_advisory_committee',
			'posts_per_page'=> -1,
			'orderby' => 'title',
			'order' => ASC
		);
	
		$member_query = new WP_Query( $args );

		if ( $member_query->have_posts()) : while ( $member_query->have_posts()) : $member_query->the_post();
        ?>
        <?php 
		$advisory_role = get('general_detail_if_advisory_committee'); 
		if ( $advisory_role == 'Committee Chair' ) {
        	$chairs[] = $post;
        } else
		if ( $advisory_role == 'Committee Co-Chair' ) {
        	$co_chairs[] = $post;
        } else {
			$last_nm = stristr( $post->post_title, ' ' );
			$ID = $post->ID;
			$members[$last_nm.$ID] = $post;
		}

		?>
       <?php endwhile; endif; ?>
	<?php if ( $chairs || $co_chairs ) { ?>
		<table cellspacing="0" class='classes-table'>
        <caption>Committee Chairpersons</caption>
        <colgroup>
			<col id="Name" />
			<col id="Title" />
			<col id="Department" />
			<col id="Email" />
			<col id="Office" />
		</colgroup>
        <thead>
		  <tr>
		  	<th scope = 'col'>Name</th>
		  	<th scope = 'col'>Title</th>
		  	<th scope = 'col'>Department</th>
		  	<th scope = 'col'>Email</th>
		  	<th scope = 'col'>Office</th>
          </tr>
		</thead>
        <tbody>
         <?php
		 if ( $chairs ) { 
			   foreach ( $chairs as $chair ) {
				   $ID = $chair->ID;
				   $salutation = get('general_detail_salutation', 1, 1, true, $ID );
				   if ( stristr( $salutation, 'ignore' ) ) { $salutation = false;  } else { $salutation = "Dr."; }
				   $dept = get('general_detail_department', 1, 1, true, $ID );
				   $email = get('contact_detail_email', 1, 1, true, $ID );
				   $rm = get('contact_detail_building_room_number', 1, 1, true, $ID );
				   $name = $salutation." ".$chair->post_title;
				   $staff = get('general_detail_if_staff', 1, 1, true, $ID );
				   if ( $staff == "Yes" ) {
					   $link_back  = add_query_arg( 'staff-member', $chair->post_name , $staff_link ); 
					   $name = "<a href='".$link_back."'>".$name."</a>";
					}
				echo 
				"<tr>
					<td>
						".$name."
					</td>
					<td>	
						Committee Chair
					</td>
					<td>
						".$dept."
					</td>
					<td>
						".$email."
					</td>
					<td>
						".$rm."
					</td>
				</tr>";
			   }   
		 }
		   if ( $co_chairs ){
		     	foreach ( $co_chairs as $co_chair ) {
				   $ID = $co_chair->ID;
				   $salutation = get('general_detail_salutation', 1, 1, true, $ID );
				   if ( stristr( $salutation, 'ignore' ) ) { $salutation = false;  } else { $salutation = "Dr."; }
				   $dept = get('general_detail_department', 1, 1, true, $ID );
				   $email = get('contact_detail_email', 1, 1, true, $ID );
				   $rm = get('contact_detail_building_room_number', 1, 1, true, $ID );
				   $name = $salutation." ".$co_chair->post_title;
				   $staff = get('general_detail_if_staff', 1, 1, true, $ID );
				   if ( $staff == "Yes" ) {
					   $link_back  = add_query_arg( 'staff-member', $co_chair->post_name , $staff_link ); 
					   $name = "<a href='".$link_back."'>".$name."</a>";
					}
				   
				echo 
				"<tr>
					<td>
						".$name."
					</td>
					<td>	
						Committee Co-Chair
					</td>
					<td>
						".$dept."
					</td>
					<td>
						".$email."
					</td>
					<td>
						".$rm."
					</td>
				</tr>";
				}  
		   }
		   ?>
        </tbody>
      </table>
	  <?php
	}
	   
	   
	//order members by last name
	if ( $members ) {
	  ksort( $members );?>
      
     <table cellspacing="0" class='classes-table'>
        <caption>Committee Members</caption>
        <colgroup>
			<col id="Name" />
			<col id="Department" />
			<col id="Email" />
			<col id="Office" />
		</colgroup>
        <thead>
		  <tr>
		  	<th scope = 'col'>Name</th>
		  	<th scope = 'col'>Department</th>
		  	<th scope = 'col'>Email</th>
		  	<th scope = 'col'>Office</th>
          </tr>
		</thead>
        <tbody>
	   <?php
       foreach ( $members as $member ) {
		   $ID = $member->ID;
		   $salutation = get('general_detail_salutation', 1, 1, true, $ID );
		   if ( stristr( $salutation, 'ignore' ) ) { $salutation = false;  } else { $salutation = "Dr."; }
		   $dept = get('general_detail_department', 1, 1, true, $ID );
		   $email = get('contact_detail_email', 1, 1, true, $ID );
		   $rm = get('contact_detail_building_room_number', 1, 1, true, $ID );
		   $name = $salutation." ".$member->post_title;
		   $staff = get('general_detail_if_staff', 1, 1, true, $ID );
		   if ( $staff == "Yes" ) {
			   $link_back  = add_query_arg( 'staff-member', $member->post_name , $staff_link ); 
			   $name = "<a href='".$link_back."'>".$name."</a>";
			}
   
			echo 
			"<tr>
				<td>
					".$name."
				</td>
				<td>
					".$dept."
				</td>
				<td>
					".$email."
				</td>
				<td>
					".$rm."
				</td>
			</tr>";
			}  
	   ?>
   		</tbody>
      </table>
    <?php }
	?>
    <?php wp_reset_postdata(); ?>
        
        <p>&nbsp;</p>
        
        <?php /* wp_link_pages(array('before' => '<p class="pages"><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); */ ?>
        <?php /* the_tags( '<p class="tags"><strong>Tags:</strong> ', ', ', '</p>'); */ ?>
        <p class="postmetadata"> Updated <span class="datetime"><?php the_time("$dateformat"); ?></span> <?php if ( $currCat[0]->category_count > '1' ) { ?>&nbsp;&nbsp; Go back to <span class="category"><?php the_category(', '); ?></span><?php } ?></p>
      
      
      </div><!-- end .column-content -->

      <?php if ($layout != 'double' && $layout != 'full') { ?><div class="column column-narrow column-last">
      
        <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar: Posts (Right)') ) : ?>&nbsp;<?php endif; ?>
      
      </div><!-- end .column-narrow -->
      <?php } ?>

<?php endwhile; endif; ?>

      <div class="clear">&nbsp;</div>

    </div><!-- end .wrap -->
  </div><!-- end #content -->

<?php get_footer(); ?>